<template>
  <a-card :bordered="false">
    <!-- 搜索区域-begin -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="12" :lg="10" :md="8" :sm="24">
             <a-form-item label="时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
               <a-range-picker
                 style="width: 260px"
                 v-model="queryParam.createTimeRange"
                 format="YYYY-MM-DD"
                 :placeholder="['开始时间', '结束时间']"
                 @change="onDateChange"
                 @ok="onDateOk"
               />
             </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="6" :md="8" :sm="24">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset1" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    <!-- 搜索区域-end -->
    <!-- table区域-begin -->
    <div v-show="showTab==1">
      <a-table
        ref="table"
        size="middle"
        
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @expand="expandRow"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
         <p slot="expandedRowRender" slot-scope="record" style="margin: 0">
             <span class="gap">单位dB:</span><span>{{weatherInfo.noises}}</span>
             <span class="gap">pm25值(0.1 ug/m3):</span><span>{{weatherInfo.pm25s}}</span>
             <span class="gap">pm10值(0.1 ug/m3):</span><span>{{weatherInfo.pm1s}}</span>
             <span class="gap">测量温度:</span><span>{{weatherInfo.mtemps}}</span>
             <span class="gap">最小风速(m/s):</span><span>{{weatherInfo.minwspeed}}</span>
             </br>
             <span class="gap">平均风速(m/s):</span><span>{{weatherInfo.avlwspeed}}</span>
             <span class="gap">最大风速(m/s):</span><span>{{weatherInfo.maxwspeed}}</span>
             <span class="gap">最小风向(m/s):</span><span>{{weatherInfo.minwdir}}</span>
         </p>
      </a-table>
    </div>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { httpAction, getAction } from '@/api/manage'
  import WeatherDataForm from '../../weatherData/modules/WeatherDataForm'
  import moment from 'moment'
  export default {
    name: 'WeatherDataList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      WeatherDataForm
    },
    data () {
      return {
        description: '天气数据管理页面',
        deviceName:'',
        indexRegisterType:"1",
        labelCol: {
          xs: { span: 1 },
          sm: { span: 2 },
        },
        wrapperCol: {
          xs: { span: 10 },
          sm: { span: 16 },
        },
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单位dB',
            align:"center",
            dataIndex: 'noises'
          },
          {
            title:'pm25值(0.1 ug/m3)',
            align:"center",
            dataIndex: 'pm25s'
          },
          {
            title:'pm10值(0.1 ug/m3)',
            align:"center",
            dataIndex: 'pm1s'
          },
          {
            title:'测量湿度(单位:%RH)',
            align:"center",
            dataIndex: 'mhumis'
          },
          {
            title:'时间',
            align:"center",
            dataIndex: 'createTime'
          },
         
        ],
        url: {
          list: "/corp/weatherData/list",
          delete: "/corp/weatherData/delete",
          deleteBatch: "/corp/weatherData/deleteBatch",
          exportXlsUrl: "/corp/weatherData/exportXls",
          importExcelUrl: "/corp/weatherData/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        weatherInfo:{}, // 通过id查询获取的气象历史数据
        // 查询条件
        queryParam: {
          createTimeRange:[],
        },
        showTab:1, //控制显示列表还是图表
      }
    },
    created() {
      this.getSuperFieldList();
      this.initDate()
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      searchReset1() {
        this.initDate()
        this.loadData(1);
      },
      changeRegisterType(e){
        this.indexRegisterType = e.target.value
        if(this.indexRegisterType=="1"){
          this.showTab = 1
          this.loadData(1)
        }else{
          this.showTab = 0
        }
      },
      initDate(){
        let date = new Date()
        var year = new Date().getFullYear()
        var month = new Date().getMonth()
        let date2 = new Date(year,month,1)
        this.date2 = moment(date2).format('YYYY-MM-DD')
        this.date = moment(date).format('YYYY-MM-DD')
        this.queryParam.createTimeRange = [moment(this.date2),moment(this.date)]
        this.queryParam.createTime_begin = this.date2
        this.queryParam.createTime_end = this.date
      },
      onDateChange: function (value, dateString) {
        this.queryParam.createTime_begin=dateString[0];
        this.queryParam.createTime_end=dateString[1];
      },
      onDateOk(value) {
        // console.log(value);
      },
      onChange(date, dateString) {
            console.log(date, dateString);
          },
      // 展开显示详情
      expandRow(expanded,record){
        if(expanded){
          this.getWeatherData({'id':record.id})
        }
      },
      // 获取气象历史数据 通过ID查询
      getWeatherData(params){
        let that = this
       let httpurl = '/corp/weatherData/queryById'
       that.confirmLoading = true;
        getAction(httpurl,params).then(res=>{
          if(res.success){
            that.weatherInfo = res.result
          }else{
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.confirmLoading = false;
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'deviceId',text:'设备id',dictCode:''})
        fieldList.push({type:'string',value:'minwspeed',text:'最小风速，m/s',dictCode:''})
        fieldList.push({type:'string',value:'avlwspeed',text:'平均风速，m/s ',dictCode:''})
        fieldList.push({type:'string',value:'maxwspeed',text:'最大风速，m/s ',dictCode:''})
        fieldList.push({type:'string',value:'minwdir',text:'最小风向，度 ',dictCode:''})
        fieldList.push({type:'string',value:'avlwdir',text:'平均风向，度',dictCode:''})
        fieldList.push({type:'string',value:'maxwdir',text:'最大风向，度 ',dictCode:''})
        fieldList.push({type:'string',value:'rains',text:'雨量，单位mm ',dictCode:''})
        fieldList.push({type:'string',value:'airkpas',text:'气压，单位hPa',dictCode:''})
        fieldList.push({type:'string',value:'radiation',text:'辐射量，单位 W/M2',dictCode:''})
        fieldList.push({type:'string',value:'ultraviolet',text:'紫外线强度等级，单位UVI',dictCode:''})
        fieldList.push({type:'string',value:'noises',text:'单位dB',dictCode:''})
        fieldList.push({type:'string',value:'pm25s',text:'pm25值, 0.1 ug/m3',dictCode:''})
        fieldList.push({type:'string',value:'pm1s',text:'pm10值, 0.1 ug/m3',dictCode:''})
        fieldList.push({type:'string',value:'mtemps',text:'测量温度',dictCode:''})
        fieldList.push({type:'string',value:'mhumis',text:'测量湿度，单位 %RH',dictCode:''})
        fieldList.push({type:'date',value:'tmstamp',text:'时间戳'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .gap{
    margin: 0 10px; 
  }
</style>